{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "16228fc1",
   "metadata": {},
   "source": [
    "* 2022/09/13/week04"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4b66c33f",
   "metadata": {},
   "source": [
    "## 上周回顾（range()) range:范围\n",
    "range(5)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "14d1553b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 5)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "16525e03",
   "metadata": {},
   "outputs": [],
   "source": [
    "# start? stop? step?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "c0e61bad",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "# for + range 决定循环的次数\n",
    "for i in range(5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "227a8c84",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,5):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "9a2dbf1f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(1, 10, 3)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(1,10,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "23b2574d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "4\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "for i in range(1,10,3):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ff14ec5c",
   "metadata": {},
   "source": [
    "# 本周内容\n",
    "\n",
    "* type():检查类型\n",
    "\n",
    "> 1. 数值\n",
    ">> 1. int(整数)\n",
    ">> 2. float（有小数）\n",
    ">> 3. complex\n",
    "\n",
    "\n",
    "> 2. 字符串\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "cc311f2f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    "c = 10\n",
    "print(c,type(c))\n",
    "   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e9c5723d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.3 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "d = 1.3\n",
    "print(d,type(d))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "107d1963",
   "metadata": {},
   "source": [
    " ## 1.Number(数值)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "cfccd3bc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 <class 'int'>\n"
     ]
    }
   ],
   "source": [
    " ## int\n",
    "    \n",
    "a = 9\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "87f865b8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "11.5 <class 'float'>\n"
     ]
    }
   ],
   "source": [
    "## float\n",
    "b = 11.5\n",
    "print(b,type(b))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "f3eb0806",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(5+3j) <class 'complex'>\n"
     ]
    }
   ],
   "source": [
    "## complex(虚数/复数)\n",
    "c = 5 + 3j\n",
    "print(c,type(c))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e8b5ea56",
   "metadata": {},
   "source": [
    "## 2.字符串（string）\n",
    "\n",
    "> 1. 关于字符串的基本内容\n",
    "> 2. 关于字符串的方法及函数"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2abee106",
   "metadata": {},
   "source": [
    "## 2.1关于字符串的基本内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "4c486126",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Alex <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "name = \"Alex\"\n",
    "print(name,type(name))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "9d7e562d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"doesn't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "73a82743",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'doesn\"t'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'doesn\"t'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9f5fb7b1",
   "metadata": {},
   "source": [
    "## 2.2关于字符串的方法及函数\n",
    "\n",
    "> 1.字符串的定义\n",
    "\n",
    "\n",
    "\n",
    "> 2.in检查成员对象\n",
    "> 3.字符串的拼接\n",
    "> 4.字符串的方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "625e5ba9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "蔡梓涵是天才\n"
     ]
    }
   ],
   "source": [
    "gg = \"蔡梓涵是天才\"\n",
    "print(gg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "66c812ed",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'蔡'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gg[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c8d017bd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(gg)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "9cbccad0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'天'"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gg[-2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "dc708e5f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州南方学院坐落于广州市从化温泉镇\n"
     ]
    }
   ],
   "source": [
    "# 关于有序性\n",
    "title = \"广州南方学院坐落于广州市从化温泉镇\"\n",
    "print (title)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "110f98d7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广'"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0]   # 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "8f1d2f98",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'南'"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[2]    # 取单一值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "cd4c6385",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "17"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(title) # 检查文本的总长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "0d024aa7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'镇'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "ad784072",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[0:6]  # 取一定范围的值，这种方法我们称其为“切片”"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "34dfd674",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'广州南方学院'"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title[:6]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1a1a5a33",
   "metadata": {},
   "outputs": [],
   "source": [
    "## enumerate 枚举，既可以获取到内容item，又可以获取到 索引值 index。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "b729aaa3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 广\n",
      "1 州\n",
      "2 南\n",
      "3 方\n",
      "4 学\n",
      "5 院\n",
      "6 坐\n",
      "7 落\n",
      "8 于\n",
      "9 广\n",
      "10 州\n",
      "11 市\n",
      "12 从\n",
      "13 化\n",
      "14 温\n",
      "15 泉\n",
      "16 镇\n"
     ]
    }
   ],
   "source": [
    "## 利用for循环 遍历文本信息\n",
    "for i,j in enumerate(title):\n",
    "    print(i,j)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "9b02c0d1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "广州这个词在这段文本中\n",
      "广州这个词在这段文本中\n"
     ]
    }
   ],
   "source": [
    "# 思考，如何判断一段文本中是否存在“广州”，例如文本 title 中的内容\n",
    "for i,j in enumerate(title):\n",
    "    if j == \"广\":\n",
    "        if title[i+1] == \"州\":\n",
    "            print(\"广州这个词在这段文本中\")\n",
    "   \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "258a6235",
   "metadata": {},
   "source": [
    "* 2.3 检查成员对象"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "e00b9854",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "## Page59  in 检查成员对象\n",
    "\"广州\" in title"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "de7b8f7e",
   "metadata": {},
   "source": [
    "* 字符串的拼接"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "30184ad2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello,Alex\n"
     ]
    }
   ],
   "source": [
    "# 字符串不可以和 数字进行连接\n",
    "print(\"hello\" +\",\"+ \"Alex\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "0584e6cd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1 <class 'int'>\n",
      "1, <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "print(1,type(1))\n",
    "print(\"1,\",type(\"1\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "2559d327",
   "metadata": {},
   "outputs": [],
   "source": [
    "#字符串 不可以 用来运算\n",
    "\"3\"/\"2\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "9693a2f5",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 由于没有分清楚 字符串和数值的概念导致的“笑话”\n",
    "width = \"16\"\n",
    "height = 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "17d1ab00",
   "metadata": {},
   "outputs": [],
   "source": [
    "面积 = width * height"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "04747205",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'161616161616161616'"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "面积"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "98953585",
   "metadata": {},
   "outputs": [],
   "source": [
    "#正确运算\n",
    "width = 16\n",
    "height = 9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "a1c75cb9",
   "metadata": {},
   "outputs": [],
   "source": [
    "面积 = width * height "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "b9a35748",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "144"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "面积"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6691014c",
   "metadata": {},
   "source": [
    "* 字符串的方法\n",
    "\n",
    ">1.str,capitalize():可以将首字母转成大写\n",
    ">2.str.count():数量？\n",
    ">3.str.split()：拆分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "8be444ad",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"marry\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "2eef216d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "ed45c44e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "name.count(\"r\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "b41a95ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.count(\"新媒体\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "eefa5881",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['广州南方学院', '广州市从化温泉镇']"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "title.split(\"坐落于\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "39dc739c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
